package com.ssm.subject.infra.basic.service.impl;

import com.alibaba.fastjson.JSON;
import com.ssm.subject.infra.basic.entity.SubjectInfo;
import com.ssm.subject.infra.basic.mapper.SubjectInfoDao;
import com.ssm.subject.infra.basic.service.SubjectInfoService;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 题目信息表(SubjectInfo)表服务实现类
 *
 * @author makejava
 * @since 2024-11-29 10:24:45
 */
@Service("subjectInfoService")
@Log4j2
public class SubjectInfoServiceImpl implements SubjectInfoService {
    @Resource
    private SubjectInfoDao subjectInfoDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SubjectInfo queryById(Long id) {
        return this.subjectInfoDao.queryById(id);
    }


    /**
     * 新增数据
     *
     * @param subjectInfo 实例对象
     * @return 实例对象
     */
    @Override
    public void insert(SubjectInfo subjectInfo) {
        this.subjectInfoDao.insert(subjectInfo);
    }

    /**
     * 修改数据
     *
     * @param subjectInfo 实例对象
     * @return 实例对象
     */
    @Override
    public int update(SubjectInfo subjectInfo) {
        return this.subjectInfoDao.update(subjectInfo);
    }

    /**
     * 统计某条件下未分页下的总数
     * @param subjectInfo
     * @param categeoryId
     * @param labelId
     * @return
     */
    @Override
    public int countByCondition(SubjectInfo subjectInfo, Long categeoryId, Long labelId) {
        int count = this.subjectInfoDao.countByCondition(subjectInfo, categeoryId, labelId);
        if(log.isInfoEnabled()) {
            log.info("SubjectInfoService.countByCondition.count:{}", count);
        }
        return count;
    }

    /**
     * 分页查询
     * @param subjectInfo
     * @param categoryId
     * @param labelId
     * @param start
     * @param pageSize
     * @return
     */
    @Override
    public List<SubjectInfo> queryPage(SubjectInfo subjectInfo, Long categoryId, Long labelId, int start, Integer pageSize) {
        List<SubjectInfo> subjectInfos = this.subjectInfoDao.queryPage(subjectInfo, categoryId, labelId, start, pageSize);
        if(log.isInfoEnabled()) {
            log.info("SubjectInfoService.queryPage.result:{}", JSON.toJSONString(subjectInfos));
        }
        return subjectInfos;
    }

    /**
     * 获取题目贡献榜
     * @return
     */
    @Override
    public List<SubjectInfo> getContributeList() {
        return subjectInfoDao.getContributeList();
    }

}
